package com.training.fragment;

import android.os.Bundle;

import com.base.BaseFragment;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.training.bean.CourseContent;
import com.training.databinding.FragmentCourseContentBinding;
import com.training.utils.DensityUtils;

public class CourseContentFragment extends BaseFragment<FragmentCourseContentBinding> {
    private CourseContent courseContent;

    @Override
    public FragmentCourseContentBinding binding() {
        return FragmentCourseContentBinding.inflate(getLayoutInflater());
    }

    @Override
    public void onCreated(Bundle savedInstanceState) {
        // 获取传递的 CourseContent 对象
        Bundle arguments = getArguments();
        if (arguments != null) {
            courseContent = (CourseContent) arguments.getSerializable("courseContent");
            int courseIndex = arguments.getInt("courseIndex");
            int courseSize = arguments.getInt("courseSize");
            if (courseContent != null) {
                mBinding.content.setText(courseContent.content);
                mBinding.index.setText(String.format("%d/%d", courseIndex + 1, courseSize));
                // 加载圆角图片
                Glide.with(context)
                        .load(courseContent.cover)
                        .transform(new RoundedCorners(DensityUtils.dp2px(context,24)))  // 16dp 圆角
                        .into(mBinding.cover);
            }
        }
    }

    @Override
    public void loadData() {

    }

    @Override
    public void refreshUI() {

    }
    
    /**
     * 获取当前Fragment的课程内容
     * @return CourseContent对象
     */
    public CourseContent getCourseContent() {
        return courseContent;
    }
}